//
//  ArticleFootView.m
//  InTime
//
//  Created by zhangjia on 15/9/9.
//  Copyright (c) 2015年 ClownYoJoy. All rights reserved.
//

#import "ArticleFootView.h"
#import "AppSizeHeader.h"
#define kContentViewHeight 20

@interface ArticleFootView ()

@property (strong, nonatomic) UIButton *collectionBtn;
@property (strong, nonatomic) UIButton *shareBtn;
@property (strong, nonatomic) UIButton *backBtn;
@property (strong, nonatomic) UIButton *nextBtn;


@end


@implementation ArticleFootView

- (void)dealloc
{
    _delegate = nil;
}


- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        CGFloat blank = (kSelfWidth - 40 - 5 * kContentViewHeight) / 3;
        self.backgroundColor = [UIColor whiteColor];
        self.alpha = 0.8;
        
        UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, (kSelfHeight - kContentViewHeight) / 2, kSelfWidth, kContentViewHeight)];
        [self addSubview:contentView];
        
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSelfWidth, 1)];
        line.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
        [self addSubview:line];
        
        self.backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.backBtn.frame = CGRectMake(20, 0, kContentViewHeight, kContentViewHeight);
        [self.backBtn setImage:[UIImage imageNamed:@"iconfont-back"] forState:UIControlStateNormal];
        [self.backBtn addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
        [contentView addSubview:self.backBtn];
        
        self.collectionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.collectionBtn.frame = CGRectMake(20 + kContentViewHeight + blank , 0, kContentViewHeight, kContentViewHeight);
        [self.collectionBtn setImage:[UIImage imageNamed:@"iconfont-unfavo"] forState:UIControlStateNormal];
        [self.collectionBtn setImage:[UIImage imageNamed:@"iconfont-favo"] forState:UIControlStateSelected];
        [self.collectionBtn addTarget:self action:@selector(collection:) forControlEvents:UIControlEventTouchUpInside];
        [contentView addSubview:self.collectionBtn];
        
        self.shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.shareBtn.frame = CGRectMake(20 + 2 * kContentViewHeight + 2 * blank, 0, kContentViewHeight, kContentViewHeight);
        [self.shareBtn setImage:[UIImage imageNamed:@"iconfont-share"] forState:UIControlStateNormal];
        [self.shareBtn addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside];
        [contentView addSubview:self.shareBtn];
        
        self.nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.nextBtn.frame = CGRectMake(kSelfWidth - 2 * kContentViewHeight - 20, 3, kContentViewHeight * 2, 14);
        [self.nextBtn setImage:[UIImage imageNamed:@"iconfont-next"] forState:UIControlStateNormal];
        [self.nextBtn addTarget:self action:@selector(next:) forControlEvents:UIControlEventTouchUpInside];
        [contentView addSubview:self.nextBtn];
        
    }
    return self;
}

- (void)setColor:(UIColor *)color {
    _color = color;
    self.backgroundColor = color;
}

#pragma mark - 按键代理方法

- (void)back:(UIButton *)button {
    if ([_delegate respondsToSelector:@selector(backToForwardView:)]) {
        [_delegate backToForwardView:button];
    }
}

- (void)collection:(UIButton *)button {
    if ([_delegate respondsToSelector:@selector(collectArticle:)]) {
        [_delegate collectArticle:button];
    }
    button.selected = !button.selected;
}


- (void)share:(UIButton *)button {
    if ([_delegate respondsToSelector:@selector(shareInfomation:)]) {
        [_delegate shareInfomation:button];
    }
}

- (void)next:(UIButton *)button {
    if ([_delegate respondsToSelector:@selector(nextPage:)]) {
        [_delegate nextPage:button];
    }
}

@end
